home *** CD-ROM | disk | FTP | other *** search
- /*************************************************************************************************
- *
- *
- * MacZoop - "the framework for the rest of us"
- *
- *
- *
- * ZApplication.h -- the application object
- *
- *
- *
- *
- *
- * © 1996, Graham Cox
- *
- *
- *
- *
- *************************************************************************************************/
-
-
- #pragma once
-
- #ifndef __ZAPPLICATION__
- #define __ZAPPLICATION__
-
- #ifndef __ZCOMMANDER__
- #include "ZCommander.h"
- #endif
-
- class ZEventHandler;
- class ZWindow;
- class ZUndoTask;
- class ZPrinter;
- class ZMenuBar;
-
- // for easier adoption of navigation services, the fileTypes handle now incorporates a
- // header such that it mimics an 'open' resource.
-
- #if PRAGMA_ALIGN_SUPPORTED
- #pragma options align=mac68k
- #endif
-
- typedef struct
- {
- OSType appSignature;
- short reserved;
- short osTypeCount;
- OSType osType[1];
- }
- FTypeList, *FTypeListPtr, **FTypeListHdl;
-
- #if PRAGMA_ALIGN_SUPPORTED
- #pragma options align=reset
- #endif
-
- // app class info:
-
- DEFINECLASSID( ZApplication, 'zapp' );
-
- // app class definition:
-
- class ZApplication : public ZCommander
- {
- friend class ZEventHandler;
-
- protected:
-
- Boolean done; // normally FALSE, if set TRUE, will try to quit
- short phase; // current phase
- short appResRefNum; // refnum of application resource file
- ZEventHandler* zEH; // event handler object
- ZWindow* mostRecent; // most recently created window
- Handle shortageFund; // to deal with tight memory, we can release this
- FTypeListHdl itsFileTypes; // list of filetypes we can open
- ZUndoTask* curUndoTask; // current undoable task
- ZPrinter* itsPrinter; // printer object for handling print commands
- Boolean memIsShort; // flag memory problem
- Boolean userHasSeenAlert; // TRUE if user has been warned about the memory
-
- public:
-
- ZApplication();
- virtual ~ZApplication();
-
- // initialisation and clean-up
-
- virtual void InitMacZoop( const short numMasterBlocks = 8 );
- virtual void StartUp() {};
- virtual void ShutDown() {};
- virtual void ReadPrefs() {};
-
- // event processing
-
- virtual void Run();
- virtual Boolean Quit();
- virtual void RequestQuit();
- virtual Boolean MemoryShortage( const Size bytesShort );
- virtual void Process1Event();
- virtual void Process1Event( EventRecord* anExternalEvent );
- virtual void HandleCommand( const long aCmd );
- virtual void HandleCommand( const short menuID, const short itemID );
- virtual void UpdateMenus();
- virtual Boolean GetCurrentEvent( EventRecord* anEvent );
- virtual void HandleAppleEvent( AEEventClass aeClass, AEEventID aeID,
- AppleEvent* aeEvt, AppleEvent* reply );
-
- virtual void MouseNotInAnyWindow( const Point globalMouse );
- virtual void WaitApplicationForeground();
- virtual void ProcessHLEvent( const EventRecord& theEvent ) {};
-
- // status utilities
-
- virtual short GetClicks();
- virtual Boolean InBackground();
- virtual void GetName( Str255 appName );
-
- // error processing
-
- virtual void HandleError( OSErr theErr );
-
- // window construction
-
- virtual void OpenNewWindow();
- virtual ZWindow* OpenNewWindowType( OSType aType = 0 );
- virtual void CloseAll( Boolean closeFloaters = FALSE );
- virtual ZWindow* GetFrontWindow();
- virtual void AboutBox();
- virtual void DoPreferences() {};
-
- // opening files
-
- virtual Boolean PickFile( FSSpec* aFile, OSType* fType );
- virtual void OpenFile( const FSSpec& aFile, const OSType fType, Boolean isStationery = FALSE );
-
- // extending the file types
-
- virtual void AddFileType( const OSType aType );
- virtual Boolean CanOpenFileType( const OSType aType );
-
- // undo task handling
-
- virtual void SetTask( ZUndoTask* aTask );
- virtual void UpdateUndo();
- inline ZUndoTask* GetUndoTask() { return curUndoTask; };
-
- // printer handling
-
- virtual void MakePrinter();
- virtual void DoPageSetup();
- virtual void DoPrint();
- inline ZPrinter* GetPrinter() { return itsPrinter; };
-
- // other inline accessors
-
- inline short GetPhase() { return phase;};
- inline FTypeListHdl GetFileTypeList() { return itsFileTypes; };
- inline Boolean MemoryCrisis() { return memIsShort; };
- inline Boolean UserHasSeenMemoryCrisisAlert() { return userHasSeenAlert; };
- inline ZEventHandler* GetEventHandler() { return zEH; };
- inline short GetAppRefnum() { return appResRefNum; };
-
- protected:
-
- void InitMacApplication( const short numMasterBlocks );
- virtual void MakeEventHandler();
- virtual void MakeClipboard();
- virtual Boolean CheckCanRun();
- virtual void InitMenuBar();
- virtual void MakeNewWindow();
- virtual ZWindow* MakeNewWindowType( OSType aType = 0 ) { MakeNewWindow(); return mostRecent; };
- virtual void CheckLowMemory();
- virtual void RegisterClasses();
- };
-
- // possible values of "phase"
-
- enum
- {
- kInitialising,
- kRunning,
- kQuitting
- };
-
- enum
- {
- kDefaultWindowType = 0
- };
-
- #define kUndoStrIndex 5
- #define kRedoStrIndex 6
- #define kCantUndoStrIndex 7
-
- #define kCantRunAlertID 131
- #define kFatalStartupErrAlertID 136
-
- #define kAEReopenApplication 'rapp' // new MacOS 8 apple event
-
-
-
- #endif